from rest_framework import serializers
from ninja import Schema, Field

from models.models import User, RegionInfo


class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'


class InvitationRecordSerializer(serializers.ModelSerializer):
    buy_water_card = serializers.SerializerMethodField()

    def get_buy_water_card(self, obj):
        # todo 获取用户购买水卡数量
        return 1

    class Meta:
        model = User
        fields = ["nickname", "openid", "phone_number", "buy_water_card", "create_time"]


class WxAppletsLoginSchema(Schema):
    """小程序登录"""
    code: str = Field(default="", max_length=32, description="code")
    phoneCode: str = Field(default="", max_length=64, description="phoneCode")
    invite_code: str = Field(default=None, description="邀请码")


class RegionInfoSerializer(serializers.ModelSerializer):

    class Meta:
        model = RegionInfo
        fields = '__all__'
